/*!
 * @file log.cpp
 * @brief Ciało log.hh
 */

#include "engine/log.hh"
using namespace std;

/*--------------------------------------------------------------------------*/

std::ofstream log::logStream("log.txt");

/*--------------------------------------------------------------------------*/

log::log(){
}

/*--------------------------------------------------------------------------*/

void log::info(std::string msg){
	log::add(msg, LOG_INFO);
}

/*--------------------------------------------------------------------------*/

void log::warning(std::string msg){
	log::add(msg, LOG_WARNING);
}

/*--------------------------------------------------------------------------*/

void log::error(std::string msg){
	log::add(msg, LOG_ERROR);
}

/*--------------------------------------------------------------------------*/

void log::crash(std::string msg){
	log::add(msg, LOG_CRASH);
}

/*--------------------------------------------------------------------------*/

void log::add(std::string str, _log_msg_type msgType) {

	stringstream newMsg;

	switch (msgType) {

	case LOG_INFO:
		newMsg << LANG_LOG_PREFIX_INFO << " ["
				<< pawirr::getFPSCount() << "]: " << str << endl;
		break;

	case LOG_WARNING:
		newMsg << LANG_LOG_PREFIX_WARNING << " ["
				<< pawirr::getFPSCount() << "]: " << str << endl;
		break;


	case LOG_ERROR:
		newMsg << LANG_LOG_PREFIX_ERROR << " ["
				<< pawirr::getFPSCount() << "]: " << str << endl;
		break;

	case LOG_CRASH:
		newMsg << LANG_LOG_PREFIX_CRASH << " ["
				<< pawirr::getFPSCount() << "]: " << str << endl;
		break;
	}

	log::logStream << newMsg.str();
	log::logStream.flush();

	cmd::execute("echo " + newMsg.str());

	if (msgType == LOG_CRASH) {
		pawirr::quit(QBRUTAL);
	}

}

/*--------------------------------------------------------------------------*/
